package net.sky.oaxz.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

import net.sky.oaxz.bean.XzGrade;
import net.sky.oaxz.bean.XzSchool;

/**
 * 操作年级
 * @author Jason
 *
 */
@SuppressWarnings("unused")
public class XzGradeDao extends BaseDao{
	private Connection conn = null;
	private PreparedStatement pstmt = null;
	private ResultSet rs = null;
	
	/**
	 * 添加年级
	 * @param 
	 * @return
	 */
	public int addGrade(XzGrade xg){
		StringBuffer sql=new StringBuffer("insert into xz_grade values (SQ_XZGRADE_ID.nextval,?,?,?,?)");
		String [] params=new String[] {xg.getGraName(),xg.getGraSeq()+"",xg.getGraDesc(),xg.getGraStatus()+""};
		return this.executeSQL(sql.toString(), params);
	}
	
	/**
	 * 显示所有年级
	 * @param schId
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public List searchGra(){
		List list =new ArrayList();
		StringBuffer sql=new StringBuffer("select * from xz_grade order by gra_seq");
		try{
			conn=this.getConn();
			pstmt=conn.prepareStatement(sql.toString());
			rs=pstmt.executeQuery();
			while(rs.next()){
				XzGrade xg=new XzGrade();
				xg.setGraId(rs.getInt("gra_id"));
				xg.setGraName(rs.getString("gra_name"));
				xg.setGraSeq(rs.getInt("gra_seq"));
				xg.setGraDesc(rs.getString("gra_desc"));
				xg.setGraStatus(rs.getInt("gra_status"));
				list.add(xg);
			}
		}catch(Exception e){
			e.printStackTrace();
		}finally{
			this.closeAll(conn, pstmt, rs);
		}
		return list;
	}
}
